//
//  CategoryViewController.m
//  Quiz
//
//  Created by Anton Atanasov on 10.02.12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "CategoryViewController.h"

@implementation CategoryViewController

@synthesize categories;
@synthesize mainFile;
@synthesize itemsInSections;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        NSString *catFile = [[NSBundle mainBundle] pathForResource:@"categories" ofType:@"plist"];
        mainFile = [[NSDictionary alloc] initWithContentsOfFile:catFile]; 
        categories = [mainFile objectForKey:@"categories"];
        //itemsInSections = [NSArray alloc] initWithObjects:m, nil
                             
    }
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return ((NSArray *)[mainFile objectForKey:@"quizes"]).count;
    //return 0;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"category"];
    }
    cell.textLabel.text = [(NSDictionary *)[(NSArray *)[mainFile objectForKey:@"quizes"] objectAtIndex: indexPath.row] objectForKey:@"name"];
    cell.detailTextLabel.text = [(NSDictionary *)[(NSArray *)[mainFile objectForKey:@"quizes"] objectAtIndex: indexPath.row] objectForKey:@"category"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
